package com.dura.strategy.filter.impl;

import com.dura.common.constant.CacheConstant;
import com.dura.common.enums.ExceptionEnums;
import com.dura.common.exception.StrategyException;
import com.dura.common.model.StandardSubmit;
import com.dura.strategy.client.BeaconCacheClient;
import com.dura.strategy.filter.StrategyFilter;
import com.dura.strategy.util.ErrorSendMsgUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 黑名单分为两种，全局黑名单、客户黑名单
 * @version 1.0
 * @Author 振鹏
 * @Date 2025/3/16 14:31
 * @注释
 */
@Service(value = "blackGlobal")
@Slf4j
public class BlackGlobalStrategyFilter implements StrategyFilter {

    @Autowired
    private BeaconCacheClient cacheClient;

    @Autowired
    private ErrorSendMsgUtil errorSendMsgUtil;

    private String TRUE="1";

    @Override
    public void strategy(StandardSubmit submit) {
        log.info("【策略模块-全局黑名单校验】 校验ing................");
        // 全局黑名单 clientId为0
        String value = cacheClient.getString(CacheConstant.BLACK + submit.getMobile());
        // redis缓存数据为1
        if(TRUE.equals(value)){
            log.info("【策略模块-全局黑名单校验】 存在黑名单，需要对其进行判断 黑名单 = {}", value);
            // 发送失败原因
            submit.setErrorMsg(ExceptionEnums.BLACK_GLOBAL.getMsg()+",mobile"+submit.getMobile());
            // 将消息发送给消息队列，分别为 系统日志和用户推送
            errorSendMsgUtil.sendWriteLog(submit);
            errorSendMsgUtil.sendPushReport(submit);
            throw new StrategyException(ExceptionEnums.BLACK_GLOBAL);
        }
        log.info("【策略模块-全局黑名单校验】   校验通过，没有黑名单信息 ,mobile={}"+submit.getMobile());
    }
}
